package com.ndp.fb.rdb.configwatch;

import com.ndp.fb.config.ConfigCentre;
import com.ndp.fb.constant.ConfigConst;
import com.ndp.fb.dubbo.container.ConfigWatcher;
import com.ndp.fb.log.LoggerConfigWatcher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * Created by yeahmobi on 2015/3/24.
 */
@Component
public class RdbConfigWatcher implements ConfigWatcher {
    protected final Log logger = LogFactory.getLog(RdbConfigWatcher.class);

    @Override
    public void notification(ApplicationContext applicationContext, String appId, Map<String, String> configmap) {
        if (appId.contains(ConfigConst.RDB_SERVICES_ID)) {
            logger.info(" MqService 配置改变了,重新初始化调度任务~！！！");
            //logger
            LoggerConfigWatcher.singleton().resetLog(configmap);
        }

    }

    @PostConstruct
    public void registWatcher() {
        ConfigCentre.addWatcher(this);
    }
}
